//
//  ViewController.m
//  TrackDemo
//
//  Created by sanfang on 2024/5/9.
//

#import "ViewController.h"

#import "KKPointModel.h"
#import "KKTrackTool.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"KML" style:UIBarButtonItemStylePlain target:self action:@selector(generateKMLFile)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"GPX" style:UIBarButtonItemStylePlain target:self action:@selector(generateGPXFile)];
}

/// 生成测试数据
- (NSArray *)generateTestData
{
    NSString* gpsStr = @"40.7128,74.0060,40.7128,74.0061,40.7128,74.0063,40.7121,74.0060,";
    NSArray* gpsArr = [gpsStr componentsSeparatedByString:@","];
    NSMutableArray *gpsPoints = [NSMutableArray array];
    for (NSInteger i = 0; i < gpsArr.count /2 ; i+= 2) {
        KKPointModel *point = [[KKPointModel alloc]init];
        point.latitude = [gpsArr[i] floatValue];
        point.longitude = [gpsArr[i +1] floatValue];
        [gpsPoints addObject:point];
    }
    return gpsPoints.copy;
}

/// 生成KML文件
- (void)generateKMLFile
{
    //测试GPS字符串
    NSArray *gpsPoints = [self generateTestData];
    [KKTrackTool generateKMLFileFromPoints:gpsPoints];
}

/// 生成gpx文件
- (void)generateGPXFile
{
     NSArray *gpsPoints = [self generateTestData];
    [KKTrackTool generateKMLFileFromPoints:gpsPoints];
}


@end
